<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>原型的基本概念 | JavaScript 高级</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.2.0">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
    

        
    
    
    <link rel="next" href="../chapter-03/section-02.html" />
    
    
    <link rel="prev" href="../chapter-03/index.html" />
    

        
    </head>
    <body>
        
        
    <div class="book" data-level="3.1" data-basepath=".." data-revision="Wed Feb 10 2016 00:11:51 GMT+0800 (CST)">
    

<div class="book-summary">
    <div class="book-search">
        <input type="text" placeholder="Type to search" class="form-control" />
    </div>
    <ul class="summary">
        
        
        
        

        

        
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        JavaScript 高级
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter-01/index.html">
            
                
                    <a href="../chapter-01/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        基本概念复习
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="chapter-02/index.html">
            
                
                    <a href="../chapter-02/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        面向对象基础
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="chapter-02/section-01.html">
            
                
                    <a href="../chapter-02/section-01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        面向对象的基本概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="chapter-02/section-02.html">
            
                
                    <a href="../chapter-02/section-02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        JavaScript 中的内置对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="chapter-02/section-03.html">
            
                
                    <a href="../chapter-02/section-03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        Array 与 Array 常用方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="chapter-02/section-04.html">
            
                
                    <a href="../chapter-02/section-04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        Date 与 Date 常用方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="chapter-02/section-05.html">
            
                
                    <a href="../chapter-02/section-05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        包装对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="chapter-02/section-06.html">
            
                
                    <a href="../chapter-02/section-06.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        自定义对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="chapter-02/section-07.html">
            
                
                    <a href="../chapter-02/section-07.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        对象字面量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="chapter-02/section-08.html">
            
                
                    <a href="../chapter-02/section-08.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        Error 对象与异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="chapter-02/section-09.html">
            
                
                    <a href="../chapter-02/section-09.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        Math 对象与全局对象
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="chapter-03/index.html">
            
                
                    <a href="../chapter-03/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        面向对象进阶
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="3.1" data-path="chapter-03/section-01.html">
            
                
                    <a href="../chapter-03/section-01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        原型的基本概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="chapter-03/section-02.html">
            
                
                    <a href="../chapter-03/section-02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        继承的概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="chapter-03/section-03.html">
            
            <span><b>3.3.</b> Object 对象</span>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="chapter-03/section-04.html">
            
            <span><b>3.4.</b> Fountion 对象</span>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="chapter-03/section-05.html">
            
            <span><b>3.5.</b> 作用域链</span>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="chapter-03/section-06.html">
            
            <span><b>3.6.</b> 闭包的基本概念</span>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="chapter-03/section-07.html">
            
            <span><b>3.7.</b> getter 与 setter</span>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="chapter-04/index.html">
            
                
                    <a href="../chapter-04/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        面向对象高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="chapter-04/section-01.html">
            
            <span><b>4.1.</b> 原型链</span>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="chapter-04/section-02.html">
            
            <span><b>4.2.</b> 对象的创建模式</span>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="chapter-04/section-03.html">
            
            <span><b>4.3.</b> 继承的方式</span>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="chapter-04/section-04.html">
            
            <span><b>4.4.</b> 函数的四中调用模式</span>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="chapter-04/section-05.html">
            
            <span><b>4.5.</b> 闭包案例</span>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="chapter-04/section-06.html">
            
            <span><b>4.6.</b> 正则表达式对象</span>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="chapter-04/section-07.html">
            
            <span><b>4.7.</b> XMLHttpRequest 对象</span>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="chapter-05/index.html">
            
                
                    <a href="../chapter-05/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        封装框架基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6" data-path="chapter-06/index.html">
            
                
                    <a href="../chapter-06/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        封装框架
                    </a>
            
            
        </li>
    


        
        <li class="divider"></li>
        <li>
            <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                Published with GitBook
            </a>
        </li>
        
    </ul>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="Table of Contents"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="Search"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="Font Settings"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">Serif</button>
        <button type="button" data-font="1" class="button">Sans</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">White</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">Sepia</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">Night</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="Share"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">
                    Share on Twitter
                </button>
                <button type="button" data-sharing="google-plus" class="button">
                    Share on Google
                </button>
                <button type="button" data-sharing="facebook" class="button">
                    Share on Facebook
                </button>
                <button type="button" data-sharing="weibo" class="button">
                    Share on Weibo
                </button>
                <button type="button" data-sharing="instapaper" class="button">
                    Share on Instapaper
                </button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Google"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
    
    
    


    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >JavaScript 高级</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="%E5%8E%9F%E5%9E%8B%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5">&#x539F;&#x578B;&#x7684;&#x57FA;&#x672C;&#x6982;&#x5FF5;</h1>
<p>&#x4E3B;&#x8981;&#x5185;&#x5BB9;:</p>
<ul>
<li>&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x6982;&#x5FF5;</li>
<li>&#x83B7;&#x5F97;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;</li>
<li>&#x4F7F;&#x7528;&#x539F;&#x578B;&#x5BF9;&#x8C61;</li>
<li><code>__proto__</code> &#x548C; <code>Object.prototype</code></li>
</ul>
<p>&#x5728; JavaScript &#x4E2D;&#x5BF9;&#x8C61;&#x662F;&#x4E00;&#x4E2A;&#x7531;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;&#x7EC4;&#x6210;&#x7684;&#x6982;&#x5FF5;. &#x8FD9;&#x53E5;&#x8BDD;&#x6BD4;&#x8F83;&#x6666;&#x6DA9;, &#x4E0B;&#x9762;&#x901A;&#x8FC7;&#x5206;&#x6790;&#x6765;&#x8BE6;&#x7EC6;&#x8BA8;&#x8BBA;&#x5BF9;&#x8C61;&#x548C;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x6982;&#x5FF5;.</p>
<h2 id="%E5%8E%9F%E5%9E%8B%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%A6%82%E5%BF%B5">&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x6982;&#x5FF5;</h2>
<h3 id="%E4%BB%80%E4%B9%88%E6%98%AF%E5%8E%9F%E5%9E%8B">&#x4EC0;&#x4E48;&#x662F;&#x539F;&#x578B;</h3>
<p>JavaScript &#x4E2D;&#x539F;&#x578B;&#x7684;&#x6982;&#x5FF5;&#x6765;&#x6E90;&#x4E8E; Self &#x8BED;&#x8A00;. Self &#x4E2D;&#x5C06;&#x7CBE;&#x7B80;&#x4F5C;&#x4E3A;&#x8BBE;&#x8BA1;&#x539F;&#x5219;. &#x8BBE;&#x8BA1;&#x4E4B;&#x521D;&#x5C31;&#x820D;&#x53BB;&#x4E86;<strong>&#x7C7B;</strong>&#x7684;&#x6982;&#x5FF5;, &#x53EA;&#x6709;<strong>&#x5BF9;&#x8C61;</strong>&#x7684;&#x6982;&#x5FF5;. &#x56E0;&#x6B64;&#x5728; JavaScript &#x4E2D;&#x51FA;&#x73B0;&#x4E86;<strong>&#x539F;&#x578B;&#x7EE7;&#x627F;</strong>&#x4E4B;&#x8BF4;, &#x5373; JavaScript &#x7684;&#x7EE7;&#x627F;&#x6240;&#x4F9D;&#x9644;&#x7684;&#x662F;&#x539F;&#x578B;&#x5BF9;&#x8C61;.</p>
<p>&#x5728; JavaScript &#x4E2D;, &#x5BF9;&#x8C61; <code>{}</code> &#x4E2D;&#x5305;&#x542B; <code>toString</code>, <code>valueOf</code>, &#x548C; <code>constructor</code> &#x7B49;&#x65B9;&#x6CD5;, &#x5B9E;&#x9645;&#x4E0A;&#x5C31;&#x662F;&#x7531;&#x539F;&#x578B;&#x7EE7;&#x627F;&#x6765;&#x5B9E;&#x73B0;&#x7684;. &#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x81EA;&#x539F;&#x578B;&#x5BF9;&#x8C61; <code>Object.property</code>.</p>
<h3 id="%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E5%8E%9F%E5%9E%8B">&#x4E3A;&#x4EC0;&#x4E48;&#x9700;&#x8981;&#x539F;&#x578B;</h3>
<p>&#x89E3;&#x91CA;&#x4E3A;&#x4F55;&#x4F7F;&#x7528;&#x539F;&#x578B;&#x4E4B;&#x524D;, &#x9996;&#x5148;&#x770B;&#x4E0B;&#x9762;&#x7684;&#x6848;&#x4F8B;.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x65B9;&#x6CD5;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.sayHello = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x4F60;&#x597D;, &#x6211;&#x662F;&#x848B;&#x5764;, &#x5F88;&#x9AD8;&#x5174;&#x8BA4;&#x8BC6;&#x4F60;!&quot;</span>);
    };
}

<span class="hljs-comment">// &#x521B;&#x5EFA;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;</span>
<span class="hljs-keyword">var</span> p1 = <span class="hljs-keyword">new</span> Person(),
    p2 = <span class="hljs-keyword">new</span> Person();

<span class="hljs-comment">// &#x8C03;&#x7528;&#x548C;&#x6BD4;&#x8F83;</span>
p1.sayHello();
p2.sayHello();
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;p1.sayHello === p2.sayHello &#x7684;&#x7ED3;&#x679C;&#x662F;: &quot;</span> +
(p1.sayHello === p2.sayHello));
</code></pre>
<p>&#x8868;&#x8FBE;&#x5F0F; <code>p1.sayHello === p2.sayHello</code> &#x7684;&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#x662F; <code>false</code>. &#x53EF;&#x89C1;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x4E24;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x65B9;&#x6CD5;.</p>
<p>&#x5728; JavaScript &#x4E2D;&#x51FD;&#x6570;&#x662F;&#x5BF9;&#x8C61;, &#x4E5F;&#x5C31;&#x662F;&#x8BF4; <code>sayHello</code> &#x65B9;&#x6CD5;&#x4E5F;&#x662F;&#x5BF9;&#x8C61;&#x7684;&#x6210;&#x5458;. &#x4E0E; <code>num = 123</code>, <code>name = &quot;&#x848B;&#x5764;&quot;</code> &#x4E00;&#x6837;, <code>sayHello</code> &#x4E5F;&#x662F;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;. &#x5728;&#x5185;&#x5B58;&#x903B;&#x8F91;&#x4E2D;:</p>
<p><img src="../images/Snip20160209_41.png" alt=""></p>
<p>&#x5982;&#x56FE;, &#x5728;&#x5185;&#x5B58;&#x4E2D;, &#x5BF9;&#x8C61; <code>p1</code> &#x548C;&#x5BF9;&#x8C61; <code>p2</code> &#x540C;&#x65F6;&#x5177;&#x6709;&#x72EC;&#x7ACB;&#x7684;&#x4E24;&#x4E2A;&#x6210;&#x5458; <code>sayHello</code>, &#x90FD;&#x5360;&#x6709;&#x5185;&#x5B58;. &#x800C; <code>sayHello</code> &#x4F5C;&#x4E3A;&#x65B9;&#x6CD5;&#x662F;&#x76F8;&#x540C;&#x7684;&#x4E00;&#x6BB5;&#x6267;&#x884C;&#x903B;&#x8F91;. &#x65E0;&#x8BBA;&#x662F;&#x4EC0;&#x4E48;&#x5BF9;&#x8C61;, &#x6267;&#x884C;&#x903B;&#x8F91;&#x90FD;&#x662F;&#x4E00;&#x6837;&#x7684;. &#x56E0;&#x6B64;&#x5E94;&#x8BE5;&#x5C06;&#x8BE5;&#x903B;&#x8F91;&#x5171;&#x4EAB;. &#x5185;&#x5B58;&#x903B;&#x8F91;&#x5E94;&#x8BE5;&#x4E3A;:</p>
<p><img src="../images/Snip20160210_42.png" alt=""></p>
<p>&#x56E0;&#x6B64;, &#x5728; JavaScript &#x4E2D;&#x6709;&#x4E86;&#x539F;&#x578B;&#x7684;&#x6982;&#x5FF5;, &#x539F;&#x578B;&#x7528;&#x6765;&#x4FDD;&#x5B58;&#x90A3;&#x4E9B;&#x5171;&#x4EAB;&#x7684;&#x6570;&#x636E;&#x548C;&#x65B9;&#x6CD5;. </p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../chapter-03/index.html" class="navigation navigation-prev " aria-label="Previous page: 面向对象进阶"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../chapter-03/section-02.html" class="navigation navigation-next " aria-label="Next page: 继承的概念"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
